package com.lyb.ui.authentication.presenter;

import com.lyb.base.BasePresenter;
import com.lyb.http.HttpManager;
import com.lyb.http.HttpSubscriber;
import com.lyb.ui.authentication.bean.GxbToken;
import com.lyb.ui.authentication.contract.GxbContract;

/**
 * Created by ls
 * 2018/12/25
 * note:
 */
public class GxbAuthPresenter extends BasePresenter<GxbContract.View> implements GxbContract.Presenter{

    public static final String TYPE_GET_TOKEN = "getToken";

    @Override
    public void getToken() {
        toSubscribe(HttpManager.getApi().getGxbToken(),new HttpSubscriber<GxbToken>(){

            @Override
            protected void _onStart() {
                mView.showLoading("获取中...");
            }

            @Override
            protected void _onNext(GxbToken gxbToken) {
                if (gxbToken!=null) {
                    mView.getTokenSuccess(gxbToken.getToken());
                }
            }

            @Override
            protected void _onError(String message) {
                mView.showErrorMsg(message,TYPE_GET_TOKEN);
            }

            @Override
            protected void _onCompleted() {
                mView.stopLoading();
            }
        });
    }
}
